import { ref } from "vue";
import type { FormInstance, FormRules } from "element-plus";

export type ruleForm = {
    user: string;
    password: string;
    checkPass: string;
};


export class InitData {
    validatePass = (rule: any, value: any, callback: any) => {
        if (value === '') {
            callback(new Error('请重新输入密码'))
        } else if (value !== this.ruleForm.checkPass) {
            callback(new Error("两次密码输入不一致!"))
        } else {
            callback()
        }
    }
    ruleForm: ruleForm = {
        user: "admin",
        password: "123456",
        checkPass: "123456",
    };
    ruleFormRef = ref<FormInstance>();
    rules: FormRules = {
        user: [
            { required: true, message: '请输入账号', trigger: 'blur' },
        ],
        password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            { min: 6, max: 10, message: '密码长度为6-10个字符长度', trigger: 'blur' },
        ],
        checkPass: [{ validator: this.validatePass, trigger: 'blur' }],
    };

}